package a01;
/**
 * @author Sven Eric Panitz
 */
import java.awt.event.*;

import static java.awt.event.KeyEvent.*;

class KeyControlledAnimation extends MouseControlledAnimation {

	private static final long serialVersionUID = 1L;

	KeyControlledAnimation(final GameObject contr) {
		super(contr);

		addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {

				switch (e.getKeyCode()) {
				case VK_LEFT:
					controlled.getDeltaPos().addMod(new Vertex(-0.5, 0));
					break;
				case VK_RIGHT:
					controlled.getDeltaPos().addMod(new Vertex(0.5, 0));
					break;
				case VK_UP:
					controlled.getDeltaPos().addMod(new Vertex(0, -0.5));
					break;
				case VK_DOWN:
					controlled.getDeltaPos().addMod(new Vertex(0, 0.5));
					break;
				}
			}
		});

		setFocusable(true);
		requestFocusInWindow();
	}
}
